Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($compile): avoid calling $onChanges() twice for NaN initial values #15098

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Sep 6, 2016

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.

What is the current behavior? (You can also link to an open issue here)
When the initial value of a binding is NaN, $onChanges() will be called twice (because we fail to detect that NaN equals NaN. For all other values, $onChanges() is called once.

What is the new behavior (if this is a feature change)?
$onChanges() is always called once, even if the initial value of a binding is NaN.

Does this PR introduce a breaking change?
No

Please check if the PR fulfills these requirements

Other information:
Discussed in #15095.

if (isFunction(destination.$onChanges) && currentValue !== previousValue) {
if (isFunction(destination.$onChanges) && currentValue !== previousValue &&
// eslint-disable-next-line no-self-compare
(currentValue === currentValue || previousValue === previousValue)) {
Copy link
Contributor

@petebacondarwin petebacondarwin Sep 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this will not trigger a call to $onChanges if we go from a real number to NaN, no?

Sorry I forgot about the currentValue !== previousValue check before it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think a test of that situation would be useful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Landed but forgot to add this extra test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the extra test. It is good excuse to fix an indentation issue 😛

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: c0cbe54

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wouldn't believe how much time I spent fixing up the indentation in my conflict editor :-)

@gkalpak gkalpak deleted the fix-compile-avoid-calling-onChanges-twice-for-NaN branch September 21, 2016 14:00
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this pull request Nov 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants